<?php
/*****************************************************
 * File name: VersionModel.php
 * Create date: 2019/03/28
 * Author: liuyue
 * Description: 技能数据库接口
 *****************************************************/

namespace Model;

use Lib;
use Lib\Paas\Login;

class SkinsModel
{
    private $db = null;

    public function __construct()
    {
        $this->db = Lib\Db\DbModel::init(); // 构造方法，线上自动切换
    }

    /**
     * 根据英雄Id以及版本Id获取英雄皮肤信息
     * @param $heroId
     * @param $versionId
     * @return array
     */
    public function getHeroSkinsInfo($heroId,$versionId)
    {
        //条件
        $where = [
            'heroId' =>$heroId,
            'versionId' =>$versionId,
            'isDelete' =>0
        ];
        $heroSkins = $this->db->table('tbskins')->where($where)->select();
        return $heroSkins;
    }



    /**
     * 根据英雄Id及版本Id获取英雄信息
     * @param $heroId
     * @param $versionId
     * @return array
     */
    public function getHeroBaseSkinsInfo($heroId,$versionId)
    {
        //英雄皮肤信息
        $skinsBaseInfo = $this->db->table('tbskins')->where([
            'heroId' => $heroId,
            'versionId' => $versionId,
            'isDelete' => 0,
            'isbase' => '1'
        ])->find();
        return $skinsBaseInfo;
    }

    /**
     * 获取英雄皮肤的详细信息
     * @param $heroId
     * @param $versionId
     * @param $skinId
     * @return array
     */
    public function getHeroDetailSkinsInfo($heroId,$versionId,$skinId)
    {
        $skinsBaseInfo = $this->db->table('tbskins')->where([
            'heroId' => $heroId,
            'versionId' => $versionId,
            'isDelete' => 0,
            'skinId' => $skinId
        ])->find();
        return $skinsBaseInfo;
    }

    /**
     * 获得套装属性配置信息
     * @return mixed
     */
    public function getSuitAttribute()
    {
        $suitAttributeInfo = $this->db->table('tbconfig')->query("select `value` from tbconfig  WHERE `alias`='skinsSuit';");

        //遍历
        foreach ($suitAttributeInfo as $key => $val)
        {
             $suitAttributeInfo[$key] = explode(",",transformComma($val['value']));
        }
        return $suitAttributeInfo;
    }

    /**
     * 编辑套装属性的值
     * @param $data
     * @return bool
     */
    public function editSuitAttribute($data)
    {

        //实例化Login类
        $login = new Login();
        $updateMan = $login->getLoginInfo()['name'];
        $update = [
            'value'=>$data,
            'updateMan' => $updateMan,
            'updateTime' => date("Y-m-d H:i:s",time())
        ];
        $res = $this->db->table('tbconfig')->where(['alias'=>'skinsSuit'])->update($update);
        if ($res){
            //日志记录
            logWrite(2,true,'tbconfig');
            return true;
        }else{
            //日志记录
            logWrite(2,false,'tbconfig');
            return false;
        }
    }
}

